/*
 * Copyright (c) 2009. Silenus Consultoria, S.L.
 */

/**
 * Module definition.
 */
MODULES['9_reports'] = {

	menu: null,

	init: function() {

		// Initialize common menu
		this.menu = new Ext.menu.Menu({
			items: [{
				text: MSG['report.action.title'],
				iconCls: 'icon-cube',
				handler: this.onActitiviesReport,
				scope: this
			}, {
				text: MSG['report.unit.title'],
				iconCls: 'icon-cube',
				handler: this.onUnitsReport,
				scope: this
			}, {
				text: MSG['report.flush.title'],
				iconCls: 'icon-cube',
				handler: this.onRefreshAnalytics,
				scope: this
			}]
		});

		// Add menu to toolbar
		Main.app.mainToolbar.add({
			text: MSG['reports.title'],
			iconCls: 'icon-rlist',
			menu: this.menu
		});
	},

	onActitiviesReport: function() {
		Main.app.addPanel({
			xtype: 'iframepanel',
			closable:true,
			loadMask: {msg: MSG['wait.message']},
			fitToParent: true,
			title: MSG['report.action.title'],
			defaultSrc: CONTEXT_PATH + '/secure/user/olap/actions.do'
		});
	},

	onUnitsReport: function() {
		Main.app.addPanel({
			xtype: 'iframepanel',
			closable:true,
			loadMask: {msg: MSG['wait.message']},
			fitToParent: true,
			title: MSG['report.unit.title'],
			defaultSrc: CONTEXT_PATH + '/secure/user/olap/units.do'
		});
	},

	onRefreshAnalytics: function() {
		Ext.Ajax.request({
			waitTitle: MSG['wait.title'],
			waitMsg: MSG['wait.message'],
			url: CONTEXT_PATH + '/secure/orgadmin/flush.json',
			params: { all: true, schema: true },
			success: function(/*response, options*/){
				notifySuccess(MSG['update'], MSG['update.success']);
			},
			failure: function(){
				notifyError(MSG['update'], MSG['update.error']);
			}
		});
	}
};